﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Slja.Model;
using Slja.BLL;
using System.IO;

namespace FrameWork.web.Web.ServiceHandler
{
    /// <summary>
    /// FileDel 的摘要说明
    /// </summary>
    public class FileDel : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string msg = "";
            bool result = false;
            try
            {
                context.Response.ContentType = "text/plain";
                // context.Response.Write("Hello World");
                int FileID = int.Parse(context.Request.Form["fileid"]);
                string FilePath = context.Request.Form["filepath"];
                string[] arr = FilePath.Split('/');
                FilePath = "/uploadFile/" + arr[arr.Length - 1];
                string absolutPath = HttpContext.Current.Server.MapPath(FilePath);
                //删除数据
                OrderFilesBLL bll = new OrderFilesBLL();
                bll.Delete(FileID);
                //删除文件
                if (File.Exists(absolutPath))
                {
                    File.Delete(absolutPath);
                }
                msg = "删除成功";
                result = true;
            }
            catch (Exception err)
            {
                msg = err.Message.Replace("'","");
                result = false;
            }
            context.Response.Write("({result:'"+result.ToString()+"',msg:'"+msg+"'})");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}